<template>
  <div class="app-container">
    <div style="display: flex; flex-direction: row">
      <div style="height: 45px">
        <el-button type="primary" @click="addProject">新增项目</el-button>
      </div>
      <div style="width: 10px" />
      <div v-show="diaplayDelete" style="height: 45px；margin-left:20px;">
        <el-button type="danger" @click="batchDelete">删除项目</el-button>
      </div>

      <div style="margin-left: 10px">
        <el-select
          v-model="projectStatus"
          class="selectInput"
          placeholder="项目状态"
          @change="selectChange(projectStatus, 1)"
        >
          <el-option
            v-for="item in is_clerk ? optionsBra : options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>

      <div style="margin-left: 10px">
        <el-select
          v-model="clerkStatus"
          class="selectInput"
          placeholder="审核状态"
          @change="selectChange(clerkStatus, 2)"
        >
          <el-option
            v-for="item in optionsClerk"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>

      <div style="margin-left: 10px">
        <el-select
          v-model="branchStatus"
          class="selectInput"
          placeholder="投标状态"
          @change="selectChange(branchStatus, 3)"
        >
          <el-option
            v-for="item in optionsBranch"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>

      <div style="margin-left: 10px">
        <el-select
          v-model="timeStatus"
          class="selectInput"
          placeholder="时间筛选"
          @change="selectChange(timeStatus, 4)"
        >
          <el-option
            v-for="item in optionsTime"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>

      <div style="margin-left: 10px">
        <el-select
          v-show="!is_clerk"
          v-model="brStatus"
          class="selectInput"
          placeholder="分公司名称"
          @change="selectChange(brStatus, 5)"
        >
          <el-option
            v-for="item in branchList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>

      <div style="margin-left: 10px">
        <el-input
          v-model="searchInfo"
          placeholder="请输入项目名称"
          prefix-icon="el-icon-search"
        />
      </div>
      <div style="margin-left: 20px;height：45px;">
        <el-button type="primary" @click="search">搜索</el-button>
      </div>
      <div style="margin-left: 20px;height：45px;">
        <el-button type="primary" @click="exportClick">导出</el-button>
      </div>
    </div>

    <el-table
      ref="tableDataRef"
      :data="projectList"
      border
      fit
      highlight-current-row
      style="width: 100%"
      :default-sort="{ prop: 'date', order: 'desce nding' }"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="40" align="center">
      </el-table-column> -->

      <el-table-column
        v-if="colData[0].istrue"
        align="center"
        prop="id"
        label="编号"
        width="60"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>

      <el-table-column
        v-if="colData[0].istrue"
        label="项目名称"
        prop="project_name"
        :show-overflow-tooltip="true"
        align="center"
      />

      <el-table-column
        v-if="colData[1].istrue"
        prop="bid_open_time"
        align="center"
        label="开标时间"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.bid_open_time | parseTime("{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>

      <el-table-column
        v-if="colData[2].istrue"
        prop="project_area"
        label="项目区域"
        :show-overflow-tooltip="true"
        align="center"
      />
      <el-table-column
        prop="price_ceiling"
        label="最高限价(万元)"
        :show-overflow-tooltip="true"
        align="center"
      />
      <el-table-column
        prop="scores"
        label="分值组成"
        :show-overflow-tooltip="true"
        align="center"
      />
      <el-table-column
        v-if="colData[2].istrue"
        prop="user_name"
        label="归属分公司"
        :show-overflow-tooltip="true"
        align="center"
      />

      <el-table-column
        v-if="colData[15].istrue"
        align="center"
        prop="project_status"
        label="项目状态"
      >
        <template slot-scope="scope">
          <span
            v-show="scope.row.project_status == 0"
            style="
              color: red;
              font: 14px Tahoma, Helvetica, Arial, '宋体', sans-serif;
              letter-spacing: 1px;
            "
          >待提交</span>
          <span
            v-show="scope.row.project_status == 1"
            style="
              color: red;
              font: 14px Tahoma, Helvetica, Arial, '宋体', sans-serif;
              letter-spacing: 1px;
            "
          >待初审</span>
          <span
            v-show="scope.row.project_status == 2"
            style="
              color: red;
              font: 14px Tahoma, Helvetica, Arial, '宋体', sans-serif;
              letter-spacing: 1px;
            "
          >待复审</span>
          <span
            v-show="scope.row.project_status == 3"
            style="
              color: red;
              font: 14px Tahoma, Helvetica, Arial, '宋体', sans-serif;
              letter-spacing: 1px;
            "
          >投标中</span>
          <span
            v-show="scope.row.project_status == 4"
            style="
              color: red;
              font: 14px Tahoma, Helvetica, Arial, '宋体', sans-serif;
              letter-spacing: 1px;
            "
          >签约中</span>
          <span
            v-show="scope.row.project_status == 12"
            style="
              color: red;
              font: 14px Tahoma, Helvetica, Arial, '宋体', sans-serif;
              letter-spacing: 1px;
            "
          >签约审核不通过</span>

          <span
            v-show="scope.row.project_status == 11"
            style="
              color: red;
              font: 14px Tahoma, Helvetica, Arial, '宋体', sans-serif;
              letter-spacing: 1px;
            "
          >签约审核中</span>

          <span
            v-show="scope.row.project_status == 8"
            style="
              color: red;
              font: 14px Tahoma, Helvetica, Arial, '宋体', sans-serif;
              letter-spacing: 1px;
            "
          >待投标</span>

          <span
            v-show="scope.row.project_status == 9"
            style="
              color: red;
              font: 14px Tahoma, Helvetica, Arial, '宋体', sans-serif;
              letter-spacing: 1px;
            "
          >待筹备</span>

          <span
            v-show="scope.row.project_status == 10"
            style="
              color: red;
              font: 14px Tahoma, Helvetica, Arial, '宋体', sans-serif;
              letter-spacing: 1px;
            "
          >已结束</span>

          <span
            v-show="scope.row.project_status == 13"
            style="
              color: red;
              font: 14px Tahoma, Helvetica, Arial, '宋体', sans-serif;
              letter-spacing: 1px;
            "
          >建设中</span>

          <span
            v-show="scope.row.project_status == 5"
            style="
              color: #1890ff;
              font: 14px Tahoma, Helvetica, Arial, '宋体', sans-serif;
              letter-spacing: 1px;
            "
          >已完成</span>
          <span
            v-show="scope.row.project_status == 6"
            style="
              color: red;
              font: 14px Tahoma, Helvetica, Arial, '宋体', sans-serif;
              letter-spacing: 1px;
            "
          >未中标</span>
          <span
            v-show="scope.row.project_status == 7"
            style="
              color: red;
              font: 14px Tahoma, Helvetica, Arial, '宋体', sans-serif;
              letter-spacing: 1px;
            "
          >初审未通过</span>
        </template>
      </el-table-column>

      <el-table-column align="center" width="200" label="操作">
        <template slot-scope="scope">
          <el-button
            v-show="
              scope.row.project_status == 0 || scope.row.project_status == 7
            "
            type="text"
            size="small"
            @click="submitAudit(scope.$index, scope.row)"
          >提交审核</el-button>
          <el-button
            type="text"
            size="small"
            @click="handleDetaile(scope.$index, scope.row, '1')"
          >项目详细</el-button>

          <el-button
            v-if="scope.row.is_audit"
            type="text"
            size="small"
            @click="handleDetaile(scope.$index, scope.row, '2')"
          >审核</el-button>
          <el-button
            v-show="
              scope.row.project_status == 0 || scope.row.project_status == 7
            "
            type="text"
            size="small"
            @click="handleEdit(scope.$index, scope.row)"
          >编辑</el-button>

          <el-button
            v-show="scope.row.project_status == 8 && is_stay_tender == true"
            type="text"
            size="small"
            @click="handleDetaile(scope.$index, scope.row, '8')"
          >待投标信息</el-button>

          <el-button
            v-show="scope.row.project_status == 9 && is_preparation == true"
            type="text"
            size="small"
            @click="handleDetaile(scope.$index, scope.row, '9')"
          >待筹备信息</el-button>

          <el-button
            v-show="scope.row.is_tender"
            type="text"
            size="small"
            @click="handleDetaile(scope.$index, scope.row, '4')"
          >投标信息</el-button>
          <el-button
            v-show="scope.row.is_signed"
            type="text"
            size="small"
            @click="handleDetaile(scope.$index, scope.row, '5')"
          >签约信息</el-button>
          <el-button
            v-show="scope.row.is_sign_audit"
            type="text"
            size="small"
            @click="handleDetaile(scope.$index, scope.row, '11')"
          >签约审核</el-button>
          <el-button
            type="text"
            size="small"
            @click="handleDetaile(scope.$index, scope.row, '3')"
          >项目评价</el-button>
          <el-button
            v-if="is_deleteShow"
            type="text"
            size="small"
            @click="handleDelete(scope.$index, scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination" style="margin-top: 10px">
      <el-pagination
        v-show="pageDisplay"
        ref="pager1"
        background
        :current-page.sync="pageIndex"
        :page-size="pageSize"
        :total="total"
        layout="prev, pager, next"
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
      />
    </div>
  </div>
</template>

<script>
import { getProject, getProjectPage, selectProject } from '@/api/project'
import { getInfo } from '@/api/user'
import {
  clerkAudit,
  sectionAudit,
  insertEvaluation,
  selectEvaluation,
  deleteProject,
  searchProject,
  batchDeleteProject,
  submitAudits,
  exportProject,
  selectProjectPage,
  searchProjectPage,
  getBranchInfo
} from '@/api/project'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'ArticleList',
  components: { Pagination },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      projectList: [],
      pageDisplay: false,
      projectStatus: '', // 筛选框model  项目状态
      clerkStatus: '',
      branchStatus: '',
      timeStatus: '',
      username: '',
      searchInfo: '', // 搜索信息
      userPermissions: [], // 当前登录用户权限数组
      is_watch_project: false, // 当前登录用户是否具有查看项目权限
      is_show: false, // 控制 项目编辑按钮显示隐藏 只有 分公司才能修改项目
      is_audit: false, // 是否具有审核的权限
      is_edit: false, // 是否具有修改权限
      is_clerkAudit: false, // 当前登录用户是否具有科员审核权限
      is_sectionAudit: false, // 当前登录用户是否具有科长审核权限
      is_tender: false, // 当前登录用户是否具有投标权限
      is_signed: false, // 当前登录用户是否具有签约权限
      is_stay_tender: false, // 当前登录用户是否具有待投标信息填写权限
      is_preparation: false, // 当前登录用户是否具有待筹备信息填写权限
      is_sign_audit: false, // 当前登录用户是否具有签约审核权限
      is_deleteShow: false, // 控制项目删除按钮显示隐藏 只有分公司具有删除功能
      dialogVisible: false, // dialog 显示隐藏
      is_clerk: false, // 是否是分公司
      diaplayDelete: false, // 是否显示批量删除
      is_clerkTwo: false, // 是否是科员
      user_id: '', // 分公司账号id
      dialogType: '', // dialog标题
      multipleSelection: [],
      brStatus: '', // 分公司筛选状态
      auditFrom: {
        status: '',
        text: '',
        clerkText: ''
      }, // 审核表单内容
      projectListId: '', // 存放点击当前行的项目id
      auditLevel: [], // 审核的职位 科员 或 科长
      clerkText: '', // 科员审核意见 用于科长审核设置默认科员意见
      dialogEvaluation: false, // 项目评价visable
      screenStatus: '', // 筛选框选中后的值 导出使用
      evaluationFrom: {
        project_id: '',
        text: '',
        username: '' // 评论人姓名
      }, // 项目评价表单内容
      valueStatus: '',
      evaluationList: '', // 评论列表
      total: 0,
      pageIndex: 1,
      pageSize: 2,
      listLoading: true,
      isSearchInfo: '', // 判断是否点击了搜索
      branchList: [],
      listQuery: {
        page: 1,
        limit: 20
      },
      optionsClerk: [
        {
          value: '初审',
          label: '初审'
        },
        {
          value: '复审',
          label: '复审'
        },
        {
          value: '审查',
          label: '审查'
        }
      ],
      optionsBranch: [
        {
          value: '待投标',
          label: '待投标'
        },
        {
          value: '待筹备',
          label: '待筹备'
        },
        {
          value: '投标中',
          label: '投标中'
        },
        {
          value: '签约中',
          label: '签约中'
        }
      ],
      optionsTime: [
        {
          value: '本月项目',
          label: '本月项目'
        },
        {
          value: '本年项目',
          label: '本年项目'
        }
      ],
      options: [
        {
          value: '全部',
          label: '全部项目'
        },
        {
          value: '未中标',
          label: '未中标'
        },
        {
          value: '建设中',
          label: '建设中'
        },
        {
          value: '已完成',
          label: '已完成'
        },

        {
          value: '已结束',
          label: '已结束'
        },
        {
          value: '审查未通过',
          label: '审查未通过'
        }
      ],
      optionsBra: [
        {
          value: '全部',
          label: '全部项目'
        },
        {
          value: '待提交',
          label: '待提交'
        },
        {
          value: '待处理',
          label: '待处理'
        },

        {
          value: '未中标',
          label: '未中标'
        },
        {
          value: '已完成',
          label: '已完成'
        },

        {
          value: '已结束',
          label: '已结束'
        },
        {
          value: '审查未通过',
          label: '审查未通过'
        }
      ],
      statusList: [
        {
          value: '通过',
          label: '通过'
        },
        {
          value: '不通过',
          label: '不通过'
        }
      ],
      colData: [
        // { title: "ID", istrue: true },
        { title: '项目名称', istrue: true },
        { title: '开标时间', istrue: true },
        { title: '项目区域', istrue: true },
        { title: '资格条件', istrue: true },
        { title: '人员要求', istrue: true },
        { title: '建设单位', istrue: true },
        { title: '代理单位', istrue: true },
        { title: '项目概况', istrue: true },
        { title: '分值组成', istrue: true },
        { title: '商务标情况', istrue: true },
        { title: '资信分情况', istrue: true },
        { title: '科员审核', istrue: true },
        { title: '科员审核意见', istrue: true },
        { title: '科长审核', istrue: true },
        { title: '科长审核意见', istrue: true },
        { title: '项目状态', istrue: true }
      ],
      colOptions: [
        // "ID",
        '项目名称',
        '开标时间',
        '项目区域',
        '资格条件',
        '人员要求',
        '建设单位',
        '代理单位',
        '项目概况',
        '分值组成',
        '商务标情况',
        '资信分情况',
        '科员审核',
        '科员审核意见',
        '科长审核',
        '科长审核意见',
        '项目状态'
      ], // 默认全选
      colSelect: [
        // "ID",
        '项目名称',
        '开标时间',
        '项目区域',
        '资格条件',
        '人员要求',
        '建设单位',
        '代理单位',
        '项目概况',
        '分值组成',
        '商务标情况',
        '资信分情况',
        '科员审核',
        '科员审核意见',
        '科长审核',
        '科长审核意见',
        '项目状态'
      ]
    }
  },
  beforeCreated() {},
  watch: {
    colOptions(valArr) {
      var arr = this.colSelect.filter((i) => valArr.indexOf(i) < 0) // 未选中
      this.colData.filter((i) => {
        if (arr.indexOf(i.title) != -1) {
          i.istrue = false
          this.$nextTick(() => {
            this.$refs.tableDataRef.doLayout()
          })
        } else {
          i.istrue = true
          this.$nextTick(() => {
            this.$refs.tableDataRef.doLayout()
          })
        }
      })
    }
  },
  created() {
    this.getUserInfo()
  },
  mounted() {},
  methods: {
    // 待投标
    stayTender() {},
    // 待筹备

    // 项目导出
    exportClick() {
      const searchValue = this.searchInfo // 搜索框的值
      const screenValue = this.screenStatus // 筛选框的值
      if (searchValue == '' && screenValue == '') {
        this.$confirm(
          '你没有筛选需要导出的数据,默认导出所有项目数据,是否继续?',
          '提示',
          {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning'
          }
        ).then(() => {
          this.exportProject(searchValue, screenValue)
        })
      } else {
        this.exportProject(searchValue, screenValue)
      }
    },
    // 导出数据具体方法
    exportProject(searchValue, screenValue) {
      let kinds = -1
      // 分公司导出
      if (this.is_clerk) {
        kinds = '2'
      }
      // 科员导出
      if (this.is_clerkTwo) {
        kinds = '1'
      }
      // 查看项目权限导出(管理员)
      if (this.is_watch_project) {
        kinds = '0'
      }
      new Promise((resolve, reject) => {
        exportProject({
          kinds: kinds,
          searchValue: searchValue,
          screenValue: screenValue
        }).then((response) => {
          const url = response.data
          const name = url.substring(url.lastIndexOf('/') + 1)
          this.$notify({
            title: '开始导出',
            duration: 2000
          })
          const x = new XMLHttpRequest()
          x.open('GET', url, true)
          x.responseType = 'blob'
          x.onload = function() {
            const urls = window.URL.createObjectURL(x.response)
            const a = document.createElement('a')
            a.href = urls
            a.download = name
            a.click()
          }
          x.send()
        })
      })
    },
    // 批量删除
    batchDelete() {
      const arr = this.multipleSelection
      const id = []
      for (let i = 0; i < arr.length; i++) {
        id.push(arr[i].id)
      }
      this.$confirm('确认删除选中项目?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        new Promise((resolve, reject) => {
          batchDeleteProject({ id: id }).then((response) => {
            if (response.data == true) {
              this.$message({
                type: 'success',
                message: '删除成功！'
              })
              this.getProjectList()
            } else {
              this.$message({
                type: 'error',
                message: '删除失败！'
              })
            }
          })
        })
      })
    },
    // 批量删除多选
    handleSelectionChange(val) {
      this.multipleSelection = val
      this.diaplayDelete = true
      if (this.multipleSelection.length == 0) {
        this.diaplayDelete = false
      }
    },
    // 搜索
    search() {
      const id = this.user_id
      const screenStatus = this.screenStatus // 筛选框的值
      this.isSearchInfo = this.searchInfo
      let kinds = ''
      // 分公司查询
      if (this.is_clerk) {
        kinds = '2'
      }
      // 科员项目查询
      if (this.is_clerkTwo) {
        kinds = '1'
      }
      // 所有项目的查询
      if (this.is_watch_project) {
        kinds = '0'
      }
      new Promise((resolve, reject) => {
        searchProject({
          value: this.searchInfo,
          id: id,
          kinds: kinds,
          screenValue: screenStatus
        }).then((response) => {
          this.projectList = response.data.data
          this.total = response.data.total
          this.pageSize = response.data.to
          this.displayButton(this.projectList)
          if (this.projectList.length == 0) {
            return (this.pageDisplay = false)
          }
          if (this.projectList.length > 0) {
            return (this.pageDisplay = true)
          }
        })
      })
    },
    submitAudit($index, row) {
      this.$confirm('项目提交审核后暂时无法修改,是否确认提交?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          new Promise((resolve, reject) => {
            submitAudits({ id: row.id }).then((response) => {
              this.$message({
                type: 'success',
                message: '提交审核成功!'
              })
              this.getProjectList()
            })
          })
        })
        .catch(() => {})
    },
    // 编辑
    handleEdit($index, row) {
      if (row.project_status == 0 || row.project_status == 7) {
        this.$router.push({ path: '/project/edit', query: { id: row.id }})
      }
    },
    // 项目详细
    handleDetaile($index, row, value) {
      const status = row.project_status
      if (value == '1') {
        this.$router.push({
          path: '/project/projectDetail',
          query: { value: value, id: row.id, status: status }
        })
      } else if (value == '2') {
        // 如果当前项目状态是1或2代表还未完成审核
        if (status == 1 || status == 2) {
          // 当权限是科长审核 项目状态是1 时 代表科员还未审核
          if (
            status == 1 &&
            this.is_sectionAudit == true &&
            this.is_clerkAudit == false
          ) {
            return this.$message({
              type: 'info',
              message: '项目待初审！'
            })
          }
          // 当权限是科员审核 项目状态是1 时
          if (
            status == 1 &&
            this.is_sectionAudit == false &&
            this.is_clerkAudit == true
          ) {
            return this.$router.push({
              path: '/project/projectDetail',
              query: { value: value, id: row.id, status: 1 }
            })
          }
          // 当权限是科长审核 项目状态是2 时
          if (
            status == 2 &&
            this.is_clerkAudit == false &&
            this.is_sectionAudit == true
          ) {
            return this.$router.push({
              path: '/project/projectDetail',
              query: { value: value, id: row.id, status: 2 }
            })
          }

          // 当权限是科员审核 项目状态是2 时
          if (
            status == 2 &&
            this.is_clerkAudit == true &&
            this.is_sectionAudit == false
          ) {
            return this.$message({
              type: 'info',
              message: '项目初审已通过，等待复审！'
            })
          }

          // 当同时拥有科员和科长审核权限时
          if (
            status == 1 &&
            this.is_sectionAudit == true &&
            this.is_clerkAudit == true
          ) {
            return this.$router.push({
              path: '/project/projectDetail',
              query: { value: value, id: row.id, status: 1 }
            })
          }

          // 当同时拥有科员和科长审核权限时
          if (
            status == 2 &&
            this.is_sectionAudit == true &&
            this.is_clerkAudit == true
          ) {
            return this.$router.push({
              path: '/project/projectDetail',
              query: { value: value, id: row.id, status: 2 }
            })
          }
        }

        if (status == 3) {
          this.$message({
            type: 'info',
            message: '项目投标中！'
          })
        }
        if (status == 4) {
          this.$message({
            type: 'info',
            message: '项目签约中！'
          })
        }
        if (status == 5) {
          this.$message({
            type: 'info',
            message: '项目已完成！'
          })
        }
        if (status == 6) {
          this.$message({
            type: 'info',
            message: '项目审核未完成！'
          })
        }
      } else if (value == '3') {
        // 项目评价
        return this.$router.push({
          path: '/project/projectDetail',
          query: { value: value, id: row.id }
        })
      } else if (value == '4') {
        if (status == 1 || status == 2) {
          return this.$message({
            type: 'info',
            message: '项目待审核！'
          })
        }
        if (status == 3) {
          this.$router.push({
            path: '/project/projectDetail',
            query: { value: value, id: row.id, status: status }
          })
        }
        if (status == 4) {
          this.$confirm('你已经填写投标信息，是否确认修改？', '提示', {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.$router.push({
              path: '/project/projectDetail',
              query: { value: value, id: row.id, update: 1 }
            })
          })
        }
        if (status == 5) {
          return this.$message({
            type: 'info',
            message: '项目已完成！'
          })
        }
        if (status == 6) {
          return this.$message({
            type: 'info',
            message: '项目审核未通过'
          })
        }
      } else if (value == '5') {
        if (status == 1 || status == 2) {
          return this.$message({
            type: 'info',
            message: '项目待审核！'
          })
        }
        if (status == 3) {
          return this.$message({
            type: 'info',
            message: '项目投标中！'
          })
        }
        if (status == 4 || status == 12) {
          this.$router.push({
            path: '/project/projectDetail',
            query: { value: value, id: row.id }
          })
        }
        if (status == 5) {
          return this.$message({
            type: 'info',
            message: '项目已完成！'
          })
        }
        if (status == 6) {
          return this.$message({
            type: 'info',
            message: '项目审核未通过！'
          })
        }
      } else if (value == '11') {
        this.$router.push({
          path: '/project/projectDetail',
          query: { value: value, id: row.id }
        })
      } else if (value == '8') {
        this.$router.push({
          path: '/project/projectDetail',
          query: { value: value, id: row.id, status: status }
        })
      } else if (value == '9') {
        this.$router.push({
          path: '/project/projectDetail',
          query: { value: value, id: row.id, status: status }
        })
      }
    },
    // 添加项目
    addProject() {
      let flag
      // 判断用户权限数组中是否有添加项目权限
      for (let i = 0; i < this.userPermissions.length; i++) {
        if (this.userPermissions[i] == 'create project') {
          flag = true
          break
        } else {
          flag = false
        }
      }
      // 有权限跳转到项目添加页面
      if (flag) {
        this.$router.push('/project/submit')
      } else {
        return this.$message({
          type: 'error',
          message: '你没有权限添加项目,请联系管理员!'
        })
      }
    },
    // 项目状态筛选
    selectChange(status, level) {
      this.screenStatus = status
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      if (level == 1) {
        this.branchStatus = ''
        this.clerkStatus = ''
        this.timeStatus = ''
        this.brStatus = ''
      }
      if (level == 2) {
        this.projectStatus = ''
        this.branchStatus = ''
        this.timeStatus = ''
        this.brStatus = ''
      }
      if (level == 3) {
        this.projectStatus = ''
        this.clerkStatus = ''
        this.timeStatus = ''
        this.brStatus = ''
      }
      if (level == 4) {
        this.projectStatus = ''
        this.clerkStatus = ''
        this.branchStatus = ''
        this.brStatus = ''
      }
      if (level == 5) {
        this.projectStatus = ''
        this.clerkStatus = ''
        this.branchStatus = ''
        this.timeStatus = ''
      }
      let kinds = ''
      // 筛选所有已提交的项目 具有查看项目权限
      if (this.is_watch_project) {
        kinds = '0'
      }
      // 分公司筛选自己的项目
      else if (this.is_clerk) {
        kinds = '2'
      }
      // 科员筛选自己所管的分公司提交的项目
      else if (this.is_clerkTwo) {
        kinds = '1'
      }
      this.pageIndex = 1
      // this.$refs.pager1.pageIndex = 1;
      new Promise((resolve, reject) => {
        selectProject({
          projectStatus: status,
          id: this.user_id,
          kinds: kinds
        }).then((response) => {
          this.projectList = response.data.data
          this.total = response.data.total
          this.pageSize = response.data.to
          this.displayButton(this.projectList)
          if (this.projectList.length == 0) {
            return (this.pageDisplay = false)
          }
          if (this.projectList.length > 0) {
            return (this.pageDisplay = true)
          }
        })
      })
      loading.close()
    },
    // 点击 x关闭审核对话框 ,清楚表达你内容
    closeAuditFrom(done) {
      this.auditFrom.clerkText = ''
      this.auditFrom.status = ''
      this.auditFrom.text = ''
      done()
    },
    // 点击 x 关闭评价对话框 清除表单输入内容
    closeEvaluationFrom(done) {
      this.evaluationFrom.text = ''
      done()
    },
    // 提交评价
    confirEvaluation() {
      new Promise((resolve, reject) => {
        insertEvaluation({ evaluationFrom: this.evaluationFrom })
          .then((response) => {
            this.$message({
              type: 'success',
              message: '评论成功!'
            })
          })
          .then(() => {
            this.selectEvaluation(this.evaluationFrom.project_id)
            this.evaluationFrom.text = ''
          })
      })
    },
    // 取消评论框
    cancelEvaluation() {
      this.dialogEvaluation = false
      this.evaluationFrom.text = ''
    },

    // 查询评论内容
    selectEvaluation(row) {
      new Promise((resolve, reject) => {
        selectEvaluation({ project_id: row }).then((response) => {
          this.evaluationList = response.data[0].projects_belongs_to_many
        })
      })
    },

    // 删除项目
    handleDelete($index, row) {
      let confirmText = ''
      switch (row.project_status) {
        case 0:
          confirmText = '项目还未提交,确认删除?'
          break
        case 1:
          confirmText = '项目正在初审,确认删除?'
          break
        case 2:
          confirmText = '项目正在复审,确认删除?'
          break
        case 3:
          confirmText = '项目投标信息填写中,无法删除!'
          break
        case 4:
          confirmText = '项目签约信息填写中,无法删除!'
          break
        case 5:
          confirmText = '项目已完成,无法删除!'
          break
        case 6:
          confirmText = '项目未中标,是否确认删除?'
          break
        case 7:
          confirmText = '项目审核不通过,是否确认删除?'
          break
        case 13:
          confirmText = '项目建设中,无法删除!'
          break
        case 8:
          confirmText = '项目待投标,确认删除?'
          break
        case 9:
          confirmText = '项目待筹备,确认删除?'
          break
        case 11:
          confirmText = '项目签约审核中,确认删除?'
          break
        case 11:
          confirmText = '项目签约审核未通过,确认删除?'
          break
      }
      this.$confirm(confirmText, '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 判断当前项目状态 签约中和投标信息填写中无法删除
        if (
          row.project_status == 3 ||
          row.project_status == 4 ||
          row.project_status == 5 ||
          row.project_status == 13
        ) {
          // console.log(1);
        } else {
          new Promise((resolve, reject) => {
            deleteProject({ id: row.id })
              .then((response) => {
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                })
              })
              .then(() => {
                this.getProjectList()
              })
          })
        }
      })
    },
    // 清除表单和关闭dialog对话框
    clearFrom() {
      this.dialogVisible = false // 关闭对话框
      this.auditFrom.status = '' // 清空dialog内表单
      this.auditFrom.text = '' // 清空dialog内表单
      this.auditFrom.clerkText = '' // 清空dialog内表单
      this.is_opinion = false // 将科员意见input 隐藏
    },
    // 下一页
    sizeChangeHandle: function(size) {
      this.pagesize = size
    },
    currentChangeHandle: function(val) {
      const screenStatus = this.screenStatus
      const searchInfo = this.isSearchInfo
      const level = 0
      let kinds = ''
      // 筛选所有已提交的项目 具有查看项目权限
      if (this.is_watch_project) {
        kinds = '0'
      }
      // 分公司筛选自己的项目
      else if (this.is_clerk) {
        kinds = '2'
      }
      // 科员筛选自己所管的分公司提交的项目
      else if (this.is_clerkTwo) {
        kinds = '1'
      }
      // console.log(kinds);
      if (screenStatus == '' && searchInfo == '') {
        return new Promise((resolve, reject) => {
          getProjectPage(val, {
            value: this.valueStatus,
            id: this.user_id
          }).then((response) => {
            this.projectList = response.data.data
            this.displayButton(this.projectList)
          })
        })
      } else if (screenStatus != '' && searchInfo == '') {
        return new Promise((resolve, reject) => {
          selectProjectPage(val, {
            projectStatus: screenStatus,
            id: this.user_id,
            kinds: kinds
          }).then((response) => {
            this.projectList = response.data.data
            this.displayButton(this.projectList)
            if (this.projectList.length == 0) {
              return (this.pageDisplay = false)
            }
            if (this.projectList.length > 0) {
              return (this.pageDisplay = true)
            }
          })
        })
      } else if (
        (screenStatus == '' && searchInfo != '') ||
        (screenStatus != '' && searchInfo != '')
      ) {
        return new Promise((resolve, reject) => {
          searchProjectPage(val, {
            value: searchInfo,
            id: this.user_id,
            kinds: kinds,
            screenValue: screenStatus
          }).then((response) => {
            this.projectList = response.data.data
            this.displayButton(this.projectList)
            if (this.projectList.length == 0) {
              return (this.pageDisplay = false)
            }
            if (this.projectList.length > 0) {
              return (this.pageDisplay = true)
            }
          })
        })
      }
    },
    // 获取项目信息
    getProjectList() {
      // 科员获取项目
      if (this.is_clerkAudit) {
        this.valueStatus = '2'
      }
      // 分公司获取项目
      if (this.is_clerk) {
        this.valueStatus = '4'
      }
      // 当权限是查看全部权限时
      if (this.is_watch_project) {
        this.valueStatus = '1'
      }
      return new Promise((resolve, reject) => {
        getProject({ value: this.valueStatus, id: this.user_id }).then(
          (response) => {
            this.projectList = response.data.data
            this.total = response.data.total
            this.pageSize = response.data.to
            this.displayButton(this.projectList)
            if (this.getProjectList != null) {
              this.pageDisplay = true
            }
          }
        )
      })
    },

    displayButton(arr) {
      // 是否具有审核权限
      if (this.is_audit) {
        for (let i = 0; i < arr.length; i++) {
          if (arr[i].project_status == 1 || arr[i].project_status == 2) {
            this.projectList[i].is_audit = true
          } else {
            this.projectList[i].is_audit = false
          }
        }
      }

      // 是否具有填写投标信息的权限
      if (this.is_tender) {
        // console.log(565);

        for (let i = 0; i < arr.length; i++) {
          if (arr[i].project_status == 3) {
            this.projectList[i].is_tender = true
            // 当项目状态为签约中时
          } else if (arr[i].project_status == 4) {
            this.projectList[i].is_tender = true
          } else {
            this.projectList[i].is_tender = false
          }
        }
      }

      //  是否具有签约权限
      if (this.is_signed) {
        for (let i = 0; i < arr.length; i++) {
          if (arr[i].project_status == 4 || arr[i].project_status == 12) {
            this.projectList[i].is_signed = true
          } else {
            this.projectList[i].is_signed = false
          }
        }
      }
      //  是否具有签约审核权限
      if (this.is_sign_audit) {
        for (let i = 0; i < arr.length; i++) {
          if (arr[i].project_status == 11) {
            this.projectList[i].is_sign_audit = true
          } else {
            this.projectList[i].is_sign_audit = false
          }
        }
      }
    },

    // 获取分公司筛选狂信息

    getBranchInfoIndex() {
      // console.log(this.user_id);
      return new Promise((resolve, reject) => {
        getBranchInfo().then((response) => {
          // console.log(response.data);
          this.branchList = response.data
        })
      })
    },

    // 获取当前用户的登录信息
    getUserInfo() {
      new Promise((resolve, reject) => {
        getInfo().then((response) => {
          this.username = response.data.name // 当前登录用户的姓名
          this.userPermissions = response.data.per // 当前登录用户权限数组
          this.user_id = response.data.id // 当前登录用户id
          if (response.data.is_clerk == '2') {
            this.is_clerk = true // 是2代表是分公司账号
          }
          if (response.data.is_clerk == '1') {
            this.is_clerkTwo = true // 是1代表是科员账号
          }
          for (let i = 0; i < this.userPermissions.length; i++) {
            // 修改权限
            if (this.userPermissions[i] == 'update project') {
              this.is_edit = true
            }
            // 查看项目权限
            if (this.userPermissions[i] == 'watch project') {
              this.is_watch_project = true
              // this.is_clerkTwo = true;
              // this.is_clerk = true;
            }
            // 删除权限
            if (this.userPermissions[i] == 'delete project') {
              this.is_deleteShow = true
            }
            // 投标权限
            if (this.userPermissions[i] == 'tender') {
              this.is_tender = true
            }
            // 待投标权限
            if (this.userPermissions[i] == 'stay tender') {
              this.is_stay_tender = true
            }
            // 待筹备权限
            if (this.userPermissions[i] == 'stay preparation') {
              this.is_preparation = true
            }
            // 签约权限
            if (this.userPermissions[i] == 'sign') {
              this.is_signed = true
            }
            // 签约审核权限
            if (this.userPermissions[i] == 'sign audit') {
              this.is_sign_audit = true
            }
            // 科员审核
            if (this.userPermissions[i] == 'clerk audit') {
              this.is_audit = true
              this.is_clerkAudit = true
              this.auditLevel.push(this.userPermissions[i])
            }
            // 科长审核
            if (this.userPermissions[i] == 'section audit') {
              this.is_audit = true
              this.is_sectionAudit = true
              this.is_clerkTwo = true // 是1代表是科员账号
              this.auditLevel.push(this.userPermissions[i])
            }
          }
          // 获取当前登录用户信息后获取项目信息
          const title = this.$route.query.type
          if (title != null) {
            if (title == '待初审') {
              this.clerkStatus = '初审'
              this.selectChange('初审', 2)
            } else if (title == '待复审') {
              this.clerkStatus = '复审'
              this.selectChange('复审', 2)
            } else if (title == '投标中') {
              this.branchStatus = '投标中'
              this.selectChange('投标中', 3)
            } else if (title == '签约中') {
              this.branchStatus = '签约中'
              this.selectChange('签约中', 3)
            } else if (title == '待提交') {
              this.projectStatus = '待提交'
              this.selectChange('待提交', 1)
            } else if (title == '本月项目') {
              this.timeStatus = '本月项目'
              this.selectChange('本月项目', 4)
            } else if (title == '本年项目') {
              this.timeStatus = '本年项目'
              this.selectChange('本年项目', 4)
            } else if (title == '已完成项目') {
              this.projectStatus = '已完成'
              this.selectChange('已完成', 1)
            } else if (title == '待处理') {
              this.projectStatus = '待处理'
              this.selectChange('待处理', 1)
            } else if (title == '审查中') {
              this.projectStatus = '审查'
              this.selectChange('审查', 2)
            } else if (title == '待投标') {
              this.branchStatus = '待投标'
              this.selectChange('待投标', 3)
            } else if (title == '待筹备') {
              this.branchStatus = '待筹备'
              this.selectChange('待筹备', 3)
            } else if (title == '已结束') {
              this.projectStatus = '已结束'
              this.selectChange('已结束', 1)
            } else if (title == '未中标') {
              this.projectStatus = '未中标'
              this.selectChange('未中标', 1)
            } else if (title == '建设中') {
              this.projectStatus = '建设中'
              this.selectChange('建设中', 1)
            }
          } else {
            this.getProjectList()
            this.getBranchInfoIndex()
          }
        })
      })
    }
  }
}
</script>

<style>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
.evaluation_dialog .el-dialog__body {
  padding: 0px 20px 30px 20px;
}
.evaluation_text {
  display: flex;
  flex-direction: row;
}
/* .no_evaluation { */
/* height: 200px;
  text-align: center;
  color: #666;
  font-size: 18px;
  line-height: 200px;
  font-weight: bold;
  letter-spacing: 1px; */
/* } */
.evaluation_dialog
  .el-dialog
  .el-dialog__body
  .el-scrollbar
  .el-scrollbar__wrap {
  overflow-x: hidden;
}
.evaluation_text {
  font-size: 18px;
}
.el-divider--horizontal {
  margin: 12px 0px;
}
.selectInput .el-input__inner {
  width: 120px;
}
/*
表格最后 长度没和父容器同宽
 */
.app-container .has-gutter .gutter {
  display: block !important;
}
</style>
